// src/api/report.ts
import request from '@/utils/request';
import type { ITurnoverStatistics, IUserStatistics, IOrderStatistics, ITop10 } from '@/types/report';

// 定义通用的日期范围参数接口
interface IDateRangeQuery {
  begin: string;
  end: string;
}

/**
 * 营业额统计接口
 * @param params - 日期范围
 */
export const getTurnoverStatistics = (params: IDateRangeQuery) => {
  return request<ITurnoverStatistics>({
    url: '/report/turnoverStatistics',
    method: 'get',
    params
  });
};

/**
 * 用户统计接口
 * @param params - 日期范围
 */
export const getUserStatistics = (params: IDateRangeQuery) => {
  return request<IUserStatistics>({
    url: '/report/userStatistics',
    method: 'get',
    params
  });
};

/**
 * 订单统计接口
 * @param params - 日期范围
 */
export const getOrderReportStatistics = (params: IDateRangeQuery) => {
  return request<IOrderStatistics>({
    url: '/report/ordersStatistics',
    method: 'get',
    params
  });
};

/**
 * 查询销量排名top10接口
 * @param params - 日期范围
 */
export const getTop10 = (params: IDateRangeQuery) => {
  return request<ITop10>({
    url: '/report/top10',
    method: 'get',
    params
  });
};

/**
 * 导出报表
 */
export const exportReport = () => {
  return request({
    url: '/report/export',
    method: 'get',
    responseType: "blob" // 指定响应类型为二进制对象
  });
};
